<?php
/**
 * Created by xuan.
 * Author: xuan
 * Date: 2018/8/4
 * Time: 18:24
 */

namespace app\api\model;
use think\Db;

class Integral extends BaseModel
{	
	protected $table = 'integral';
	
	public static function selectOneIntegralByID($id){
		$data = model("Integral")->where(array("id"=>$id))->find();
		return $data;
	}
	
	public static function selectOneGoodsByOid($all){
		$data = model("Integral")->where(array("oid"=>$all['oid'],"mid"=>$all['mid']))->find();
		return $data;
	}
	
	public static function IntegralLists(){
		$data = model("Integral")->select();
		return $data;
	}
	
	public static function addOneIntegral($all)
    {
		$data = Integral::create([
			'oid' => $all['oid'],
			'goodsid' => $all['goodsid'],
			'goodsname' => $all['goodsname'],
			'sigprice' => $all['sigprice'],
			'total' => $all['total'],
			'mid' => $all['mid'],
			'fid' => $all['fid'],
			'mtel' => $all['mtel'],
			'ispay' => 2,
			'courier_num' => $all['courier_num'],
			'receive_name' => $all['receive_name'],
			'receive_tel' => $all['receive_tel'],
			'receive_addr' => $all['receive_addr'],
			'paytime' => date('Y-m-d H:i:s',time()),
			'addtime' => date('Y-m-d H:i:s',time()),
			'updatetime' => date('Y-m-d H:i:s',time())
		]);
		  
		return $data;
    }
	
	public static function updOneIntegral($all)
    {
		$data=Db::name('Integral')-> where('id',$all['id'])->update([
			'multipic' => $all['multipic'],
			'Integralname' => $all['Integralname'],
			'Integralby' => $all['Integralby'],
			'catid' => $all['catid'],
			'isshow' => $all['catid'],
			'stock' => $all['stock'],
			'price' => $all['price'],
			'superreward' => $all['superreward'],
			'bigreward' => $all['bigreward'],
			'agentprice' => $all['agentprice'],
			'detail' => $all['detail'],
			'updatetime' => date('Y-m-d H:i:s',time())
		]);
		return $data;
    }
	
	public static function delOneIntegral($id)
    {
		$data=Db::name('Integral')-> where('id',$id)->delete();
		return $data;
    }
	
	/**
     * @param $where
     * @return array|false|\PDOStatement|string|\think\Model
     * 查询详情
     */
    public static function getListByWhere($where, $page = 0, $pageSize = 10){
		$pageSize = $pageSize <= 0 ? 10 : $pageSize;
        $list = Db::name('Integral')->where($where)->limit($page, $pageSize)->order('id DESC')->select();
		return $list;
    }
	
	public static function getCount($where = ''){
        return model("Integral")->name('integral')->where($where)->count();
    } 
	
	public static function getCount2($where){
        return model("Integral")->name('integral')->where($where)->sum('intergnum');
    } 
	
}